#include"../mqserver/mq_consumer.hpp"
#include<gtest/gtest.h>
bitmq::ConsumerManager::ptr cmp;

class Consumer_Test:public testing::Environment{
    public:
    virtual void SetUp()override
    {
        cmp=std::make_shared<bitmq::ConsumerManager>();
        cmp->initQueueConsumer("queue1");
        //std::cout<<"数据的初始化完成！"<<std::endl;
    }
    virtual void TearDown()override
    {
        cmp->clear();
    }
};
//const std::string&,const BasicProperties*bp,const std::string&
void cb(const std::string&tag,const bitmq::BasicProperties*bp,const std::string&body)
{
    std::cout<<"1";
}
TEST(consumer_test,insert_test)
{
    cmp->creater("consumer1","queue1",false,cb);
    cmp->creater("consumer2","queue1",false,cb);
    cmp->creater("consumer3","queue1",false,cb);

    ASSERT_EQ(cmp->exists("consumer1","queue1"),true);
    ASSERT_EQ(cmp->exists("consumer2","queue1"),true);
    ASSERT_EQ(cmp->exists("consumer3","queue1"),true);
}

TEST(consumer_test,remove_test)
{
    
    cmp->remove("consumer1","queue1");

    ASSERT_EQ(cmp->exists("consumer1","queue1"),false);
    ASSERT_EQ(cmp->exists("consumer2","queue1"),true);
    ASSERT_EQ(cmp->exists("consumer3","queue1"),true);
    //cp=cmp->choose("queue1");

}
TEST(consumer_test,choose_test)
{
    bitmq::Consumer::ptr cp=cmp->choose("queue1");
    ASSERT_NE(cp.get(),nullptr);
    ASSERT_EQ(cp->_tag,"consumer2");

     cp=cmp->choose("queue1");
    ASSERT_NE(cp.get(),nullptr);
    ASSERT_EQ(cp->_tag,"consumer3");

     cp=cmp->choose("queue1");
    ASSERT_NE(cp.get(),nullptr);
    ASSERT_EQ(cp->_tag,"consumer2");
}
int main(int argc,char*argv[])
{
    testing::InitGoogleTest(&argc,argv);
    testing::AddGlobalTestEnvironment(new Consumer_Test);
    RUN_ALL_TESTS();
    return 0;
}